home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / AMISL083.ARJ / SWITCHAR.ASM < prev    next >
Assembly Source File  |  1992-04-19  |  9KB  |  305 lines

  1. ;-----------------------------------------------------------------------
  2. ; SWITCHAR.ASM  Public Domain 1992 Ralf Brown
  3. ;        You may do with this software whatever you want, but
  4. ;        common courtesy dictates that you not remove my name
  5. ;        from it.
  6. ;
  7. ; Provide the undocumented switch-character services which were removed
  8. ; from MSDOS 5.0.  The TSR is larger than necessary because it is
  9. ; illustrating the use of both private INT 2Dh functions and a private
  10. ; API entry point.
  11. ;
  12. ; Version 0.80
  13. ; LastEdit: 4/19/92
  14. ;-----------------------------------------------------------------------
  15.  
  16. __TINY__ equ 1                ; using Tiny model
  17.     INCLUDE AMIS.MAC
  18.  
  19. ;-----------------------------------------------------------------------
  20. ;
  21. VERSION_NUM equ 0050h    ; v0.80
  22. VERSION_STR equ "0.80"
  23.  
  24. ;-----------------------------------------------------------------------
  25. ; Declare our segments in the order we want them in the executable.
  26. ;
  27. _TEXT    SEGMENT PUBLIC BYTE 'CODE'
  28. _TEXT    ENDS
  29. TSRcode@
  30. TSRcodeEnd@
  31.  
  32. ;-----------------------------------------------------------------------
  33. ; Put the resident code into its own segment so that all the offsets are
  34. ; proper for the new location after copying it into a UMB or down into
  35. ; the PSP.
  36. ;
  37. TSRcode@
  38. start_TSRcode label byte
  39.  
  40. ;-----------------------------------------------------------------------
  41. ; Declare data storage for the TSR
  42. ;
  43.  
  44. switchar_active  db 1
  45. current_switchar db '/'
  46.  
  47. ;-----------------------------------------------------------------------
  48. ; Define the private API entry point handler
  49. ;
  50. switchar_API proc far
  51.     cmp    al,1
  52.     ja    switchar_API_done
  53.     xchg    byte ptr RESIDENT_CODE:switchar_active,al
  54. switchar_API_done:
  55.     ret
  56. switchar_API endp
  57.  
  58. ;-----------------------------------------------------------------------
  59. ; Define our private INT 2Dh function
  60. ;
  61. private:
  62.     cmp     al,10h            ; INT 2D/AH=mpx/AL=10h is set-state
  63.     jne    not_private_func
  64.     mov    al,bl            ; BL=new state
  65.     push    cs
  66.     call    near ptr switchar_API
  67.     mov    ah,al            ; return previous state
  68.     mov    al,0FFh            ; indicate success
  69.     iret
  70.  
  71. not_private_func:
  72.     mov    al,0            ; indicate not supported
  73.     iret
  74.  
  75. ;-----------------------------------------------------------------------
  76. ; Define our removal code
  77. ;    deactivate, then report that we don't have a resident uninstaller
  78. ;    but are now disabled
  79. ;
  80. remov:
  81.     mov    RESIDENT_CODE:switchar_active,0
  82.     mov    bx,0            ; seg of block to free (will be patched)
  83. ALTMPX$PSP equ word ptr ($-2)        ; magic name of word to be patched with
  84.                     ; actual memory block segment by TSR
  85.                     ; installation code
  86.     mov    al,4            ; no resident remover, now disabled
  87.     ret
  88.  
  89. ;-----------------------------------------------------------------------
  90. ; Declare the interrupt vectors hooked by the program, then set up the
  91. ; Alternate Multiplex Interrupt Spec handler
  92. ; Note: the resident remover must precede the ALTMPX if it defines ALTMPX$PSP
  93. ;    otherwise ALTMPX$PSP will be multiply-defined
  94. ;
  95.     HOOKED_INTS 21h            ; hooking INT 21h in add. to INT 2Dh
  96.     ALTMPX    'Ralf B','SWITCHAR',VERSION_NUM,'Switch-character support',private,switchar_API,,remov,Y
  97.  
  98. ;-----------------------------------------------------------------------
  99. ; Now the meat of the resident portion, the MSDOS interrupt handler.
  100. ; We can save one byte by specifying the hardware reset handler set up by
  101. ; the ALTMPX macro above
  102. ;
  103.     ISP_HEADER 21h,hw_reset_2Dh
  104.     cmp    ah,37h            ; switchar/availdev call?
  105.     jne    use_old_int21
  106.     cmp    switchar_active,0    ; is TSR enabled?
  107.     je    use_old_int21        ; if not, pass through
  108.     cmp    al,1            ; check if switchar call
  109.     ja    use_old_int21        ; if not, pass through
  110.     mov    al,0            ; always return 'success'
  111.     jb    get_switchar
  112. set_switchar:
  113.     mov    current_switchar,dl
  114.     iret
  115.  
  116. get_switchar:
  117.     mov    dl,current_switchar
  118.     iret
  119.  
  120. use_old_int21:
  121.     jmp    ORIG_INT21h
  122.  
  123. resident_code_size equ offset $
  124.  
  125. TSRcodeEnd@
  126.  
  127. ;-----------------------------------------------------------------------
  128.  
  129. _TEXT SEGMENT 'CODE'
  130.     ASSUME cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
  131.     ORG 100h
  132.  
  133. SWITCHAR:
  134.     DISPLAY_STRING banner
  135.     CHECK_DOS_VER 2,00
  136.     mov    bx,1000h        ; set memory block to 64K
  137.     mov    ah,4Ah            ; to have some memory to allocate
  138.     int    21h
  139.     mov    si,81h            ; SI -> commandline
  140.     cld
  141. cmdline_loop:
  142.     lodsb
  143.     cmp    al,' '            ; skip blanks and tabs on commandline
  144.     je    cmdline_loop
  145.     cmp    al,9
  146.     je    cmdline_loop
  147.     mov    ah,al            ; remember exact switch character
  148.     and    al,0DFh            ; force to uppercase
  149.     cmp    al,'R'
  150.     je    removing
  151.     cmp    al,'I'
  152.     je    installing
  153.     cmp    al,'E'
  154.     je    enabling
  155.     cmp    al,'D'
  156.     je    disabling
  157.         cmp     ah,' '
  158.     jbe    show_usage
  159.     jmp    set_switch_char
  160.  
  161. show_usage:
  162.     mov    dx,offset _TEXT:usage
  163.     jmp    exit_with_error
  164.  
  165. removing:
  166.     UNINSTALL <offset _TEXT:start_TSRcode>,RELBYTE,cant_uninstall
  167.     mov    dx,offset _TEXT:removed_msg
  168. exit_with_message:
  169.     mov    ah,9
  170.     int    21h
  171.         mov     ax,4C00h
  172.     int    21h
  173.  
  174. enabling:
  175.     IF_INSTALLED <offset _TEXT:start_TSRcode>,RELBYTE,enable_TSR
  176. not_installed:
  177.     mov    dx,offset _TEXT:not_installed
  178.     jmp    exit_with_error
  179.  
  180. disabling:
  181.     IF_INSTALLED <offset _TEXT:start_TSRcode>,RELBYTE,disable_TSR
  182.     jmp    not_installed
  183.  
  184. installing:
  185.     INSTALL_TSR <offset _TEXT:start_TSRcode>,RELBYTE,resident_code_size,BYTE,,BEST,,inst_notify,already_installed,cant_install
  186.  
  187. cant_uninstall:
  188.         mov     dx,offset _TEXT:cant_remove_msg
  189.     jmp short exit_with_error
  190. already_installed:
  191.     mov    dx,offset _TEXT:already_inst_msg
  192. exit_with_error:
  193.     mov    ah,9
  194.     int    21h
  195.     mov    ax,4C01h
  196.     int    21h
  197.  
  198. set_switch_char:
  199.     mov    dl,ah
  200.     push    dx
  201.     mov    ax,3701h
  202.     int    21h
  203.     pop    cx            ; get back requested switch character
  204.     mov    dx,offset _TEXT:not_supported_msg
  205.     cmp    al,0            ; supported?
  206.     jne    set_switch_done        ; branch if not
  207.     mov    ax,3700h
  208.     int    21h            ; get current switch character
  209.     cmp    dl,cl            ; now same as request switch char?
  210.     mov    dx,offset _TEXT:switchar_set_msg
  211.     je    set_switch_done
  212.     mov    dx,offset _TEXT:not_set_msg
  213. set_switch_done:
  214.     jmp    exit_with_message
  215.  
  216. cant_install:
  217.     mov    dx,offset _TEXT:cant_install_msg
  218.     jmp    exit_with_error
  219.  
  220. inst_notify:
  221.     DISPLAY_STRING _TEXT:installed_msg
  222.     ret
  223.  
  224. ;-----------------------------------------------------------------------
  225. ; on entry, AH=multiplex number
  226. ;
  227. ; for this example program, the 'enable' call will be made via a private
  228. ; INT 2Dh function, while the 'disable' call will be made via the FAR
  229. ; CALL entry point.
  230. ;
  231.  
  232. enable_TSR proc
  233.     mov    al,10h            ; private func, "set state"
  234.     mov    bl,1            ; new state = enabled
  235.     int    2Dh            ; set state, returns AH=old state
  236.     mov    al,ah
  237.     mov    dx,offset _TEXT:enabled_msg
  238. display_state_and_exit:
  239.     push    ax            ; remember prior state
  240.     mov    ah,9            ; display string
  241.     int    21h
  242.     pop    ax            ; get back prior state
  243.     mov    dx,offset _TEXT:was_on_msg
  244.     cmp    al,0
  245.     jne    display_state
  246.     mov    dx,offset _TEXT:was_off_msg
  247. display_state:
  248.     jmp    exit_with_message
  249. enable_TSR endp
  250.  
  251. ;-----------------------------------------------------------------------
  252. ; on entry, AH=multiplex number
  253. ;
  254. ; for this example program, the 'enable' call will be made via a private
  255. ; INT 2Dh function, while the 'disable' call will be made via the FAR
  256. ; CALL entry point.
  257. ;
  258.  
  259. disable_TSR proc
  260.     mov    al,1            ; function "get API entry"
  261.     int    2Dh    
  262.     cmp    al,0FFh            ; supported?
  263.     jne    disable_not_supported
  264.     mov    word ptr _TEXT:entry_point+2,dx
  265.     mov    word ptr _TEXT:entry_point,bx
  266.     mov    al,0            ; function is disable
  267.     call    dword ptr _TEXT:entry_point
  268.     mov    dx,offset _TEXT:disabled_msg
  269.     jmp    display_state_and_exit
  270. disable_not_supported:
  271.     mov    dx,offset _TEXT:cant_disable_msg
  272.     jmp    exit_with_error
  273. disable_TSR endp
  274.  
  275. ;-----------------------------------------------------------------------
  276.  
  277. banner    db 'SWITCHAR v',VERSION_STR,'  Public Domain 1992 Ralf Brown',13,10,'$'
  278. usage    db 'Usage:',9,'SWITCHAR i',9,'install',13,10
  279.     db 9,'SWITCHAR r',9,'remove from memory',13,10
  280.     db 9,'SWITCHAR d',9,"disable TSR but don't unload",13,10
  281.     db 9,'SWITCHAR e',9,'enable TSR',13,10
  282.     db 9,'SWITCHAR <x>',9,'set switch character to <x>',13,10
  283.     db '$'
  284. not_installed_msg db "Not " ;continues on next line
  285. installed_msg     db "Installed.",13,10,"$"
  286. cant_install_msg db "Unable to install.",13,10,"$"
  287. already_inst_msg db "Already installed.",13,10,"$"
  288. cant_remove_msg  db "Can't remove from memory.",13,10,"$"
  289. removed_msg     db "Removed.",13,10,"$"
  290. switchar_set_msg db "Switch character has been set.",13,10,"$"
  291. not_set_msg      db "Switch character has NOT been set.",13,10,"$"
  292. not_supported_msg db "Switch character not supported.",13,10,"$"
  293. enabled_msg     db "SWITCHAR enabled $"
  294. disabled_msg     db "SWITCHAR disabled $"
  295. was_on_msg     db "(was enabled).",13,10,"$"
  296. was_off_msg     db "(was disabled).",13,10,"$"
  297. cant_disable_msg db "Can't disable SWITCHAR.",13,10,"$"
  298.  
  299. entry_point dd ?
  300. _TEXT ENDS
  301.  
  302.      end SWITCHAR
  303.  
  304.  
  305.